home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / mini / Virtual-wu-ftpd < prev    next >
Text File  |  1997-02-02  |  12KB  |  329 lines

  1.  
  2. Virtual FTP-servers with wu-ftpd           Winfried Trⁿmper <winni@xpilot.org>
  3. --------------------------------           with help from
  4.                                            Brian Grossman <brian@SoftHome.Net>
  5.                                            Version 1.2                27.01.97
  6.  
  7.     
  8.  
  9.   1. Introduction
  10.  
  11.         Linux has the ability to run several "hosts" on one machine.
  12.         Many people already use this to run more than 1 WWW-Service on
  13.         their Linux box, e.g. 
  14.  
  15.                 www.sharpers.com                (192.168.55.37)
  16.                 www.usurers.com                 (192.168.55.38)
  17.                 www.swindlers.com               (192.168.55.39)
  18.  
  19.  
  20.         appear as if they were 3 different hosts but in fact there is
  21.         only one Linux-PC serving them.
  22.  
  23.         The technique behind this feature is called "multihoming" and
  24.         based on the ability of Linux to assign several IP-addresses
  25.         to one network-interface (ethernet-card or modem). In effect,
  26.         you do not need several ethernet-cards to make Linux listen to
  27.         several addresses/hostnames on the net.
  28.         Linux handles the additional IP-addresses through so called 
  29.         "virtual interfaces" which physically represent the same 
  30.         hardware but are logically distinguished with their ip-addresses
  31.         by the software (and the kernel).
  32.  
  33.         Those virtual interfaces are labeled similar than the main
  34.         interface they "point" to and are simply suffixed by a (more or
  35.         less) arbitrary number.
  36.         The proper term for such a virutal interfaces is "ip-alias". For
  37.         the virtual hosts above, the command "ifconfig" gives the (heavily
  38.         edited) output:
  39.  
  40.  
  41.         interface IP-address     broadcast-address       netmask
  42.         ------------------------------------------------------------
  43.         eth0      192.168.55.37    192.168.55.63     255.255.255.224
  44.  
  45.         eth0:0    192.168.55.38    192.168.55.63     255.255.255.224
  46.         eth0:1    192.168.55.39    192.168.55.63     255.255.255.224
  47.         eth0:2    192.168.55.40    192.168.55.63     255.255.255.224
  48.         eth0:3    192.168.55.41    192.168.55.63     255.255.255.224
  49.              ^-- no. of the ip-alias
  50.          
  51.  
  52.         To be able to use the facility of ip-aliases you need a "module"
  53.         for the Linux-kernel that can be fixated into the kernel when
  54.         compiling or loaded at run-time by issuing the command (as root):
  55.  
  56.                 insmod ipalias
  57.  
  58.         Most modern distributions should provide this module so I don't
  59.         want to waste time in describing how to create it (hint: if it's
  60.         missing, read the Linux Kernel-HOWTO).
  61.  
  62.         The ip-aliases for the hosts above are created with a little
  63.         shell-script when booting:
  64.  
  65. 8<----- cut here 8<-----
  66. #!/bin/sh
  67.  
  68. NETMASK="255.255.255.224"      # replace with YOUR netmask
  69. BROADCAST="192.168.55.63"      # replace with YOUR broadcast-address
  70. MAIN_IF="eth0"                 # "main" interface
  71.  
  72. IPALIASES="192.168.55.38   192.168.55.39   192.168.55.40 \
  73.            192.168.55.41   192.168.55.42   192.168.55.43 \
  74.            192.168.55.44   192.168.55.45   192.168.55.46"
  75.  
  76. # you should not need to modify anything below
  77. i=0
  78. for ALIAS in $IPALIASES
  79. do
  80.     /sbin/ifconfig  ${NETTYPE}:${i}  ${ALIAS} \
  81.                     broadcast ${BROADCAST}  netmask ${NETMASK}
  82.     /sbin/route add -host ${ALIAS} dev ${NETTYPE}:${i}
  83.     i=$[$i+1]
  84. done
  85. 8<----- cut here 8<-----
  86.  
  87.  
  88.         If you have further questions about ip-aliases, please look at
  89.         the Linux "IP Alias mini-HOWTO" and the file 
  90.         "Documentation/aliases.txt" from the sources of the Linux-kernel
  91.         (usally in the directory "/usr/src/linux"). 
  92.  
  93.  
  94.  
  95.  
  96.   2. Virtual Services and Servers
  97.  
  98.         If a hostname belongs to an virtual interface, it is commonly
  99.         called "virtual host".
  100.         A daemon that runs a service on a virtual host (or a virtual
  101.         interface) is called "virtual server".
  102.  
  103.  
  104.   2.1. Virtual WWW-Servers
  105.  
  106.         We already had an example for 3 virtual WWW-Servers above:
  107.  
  108.                 www.sharpers.com, www.usurers.com, www.swindlers.com
  109.  
  110.  
  111.         The configuration of all major http-daemons I know (e.g. the
  112.         well-designed "Roxen Challenger" or the widespread "Apache")
  113.         to make use of the virtual hosts is easy and already well
  114.         documented.
  115.         In short: just bind the www-port (no. 80) to the virtual network
  116.         interface with the desired ip-address/hostname for each 
  117.         WWW-server you run. There is no trick.
  118.  
  119.         Read the Linux "Virtual Web mini-HOWTO" to get more information
  120.         on this issue.
  121.  
  122.  
  123.   2.2. Virtual mail-addresses
  124.  
  125.         In the simplest case you want to recieve mail for all your
  126.         virtual hosts and for the dedicated domains:
  127.  
  128.                 www.sharpers.com, www.usurers.com, www.swindlers.com,
  129.                     sharpers.com,     usurers.com,     swindlers.com
  130.  
  131.  
  132.         Even the configuration of "smail" or "sendmail" (the daemons
  133.         that handle the mail-traffic on you Linux-box) is relativly
  134.         easy: mention the additional hostnames/domains in
  135.         "/etc/smail/config" (entries 'hostnames='), resp.
  136.         "/etc/mail/sendmail.cw" (each hostname on a seperate line).
  137.  
  138.         To implement a "real" virtual domain featuring smail, please
  139.         look at the smail-FAQ available from
  140.  
  141.                 http://www.sbay.org/smail-faq.html
  142.  
  143.  
  144.   2.3. Virtual ftp-servers
  145.  
  146.         The concept of a virtual ftp-server is not supported by
  147.         default for any ftp-daemon I know.
  148.  
  149.         What regards to the widespread used daemon "wu-ftpd", there
  150.         is a patch by Brian Grossman <brian@SoftHome.Net> to make the
  151.         anonymous FTP-service distinguish between the virtual 
  152.         interfaces. Availability is mentioned in chapter 3.
  153.  
  154.         There seem to be no other patches around that do the same.
  155.  
  156.  
  157.         The main idea of the Brian's multihome-patch for is to make 
  158.         wu-ftpd "chroot()" to
  159.  
  160.                 HOME_DIRECTORY_OF_ftp-ACCOUNT/HOSTNAME_THE_USER_TALKS_TO/
  161.  
  162.         instead of just doing a chroot() into
  163.  
  164.                 HOME_DIRECTORY_OF_ftp-ACCOUNT/
  165.  
  166.  
  167.         In the example shown below, the user thats connects to
  168.         "ftp.swindlers.com" via anonymous ftp is locked up under
  169.         "/home/ano-ftp/ftp.swindlers.com/" instead of just under
  170.         "/home/ano-ftp/".
  171.         You can imagine that the basic setup is straightforward and
  172.         does not differ much from setting up a single anoymous ftp-account.
  173.  
  174.         Kudos to Brian for this easy and efficient setup-strategy.
  175.  
  176.  
  177.         Let me assume you would already have this special version of
  178.         wu-ftpd compiled youself or fetched the binaries and let me
  179.         postpone all realated questions to the end of this document.
  180.  
  181.         I will give you a real-world example and tell you what I did
  182.         for one of my customers (I only changed the machine names to
  183.         non-existant ones ...).
  184.  
  185.  
  186.     (a) Created a directory "/home/ano-ftp" to incorporate the different
  187.         anonymous ftp-servers.
  188.  
  189.                 mkdir  /home/ano-ftp  &&  cd /home/ano-ftp
  190.                 mkdir  ftp.sharpers.com  ftp.usurers.com  ftp.swindlers.com
  191.  
  192.         Resulting in a tree:
  193.  
  194.         /home/ano-ftp/
  195.                   |-- ftp.sharpers.com
  196.                   |-- ftp.swindlers.com
  197.                   `-- ftp.usurers.com
  198.  
  199.  
  200.     (b) Copied the necessary files for an anonymous ftp-service from the
  201.         already configured anonymous-ftp-directory "/home/ftp" into the
  202.         newly created directories
  203.  
  204.                 cd     /home/ano-ftp/ftp.sharpers.com
  205.                 cp -a  /home/ftp/* .
  206.  
  207.                 cd     ../ftp.swindlers.com
  208.                 cp -a  /home/ftp/* .
  209.  
  210.                 cd     ../ftp.usurers.com
  211.                 cp -a  /home/ftp/* .
  212.  
  213.  
  214.         Don't forget to delete the superfluous files under "pub/"
  215.         afterwards (or simply don't copy them at all).
  216.         For example, the "/home/ftp" the Debian-distribution provides looks
  217.         like 
  218.  
  219.  
  220.         /home/ftp                       Permissions    Owner  Group   Size
  221.                 |-- bin                 d--x--x--x   2 root   root       
  222.                 |   |-- gzip            ---x--x--x   1 root   root   45121
  223.                 |   |-- ls              ---x--x--x   1 root   root   22945
  224.                 |   `-- tar             ----------   1 root   root   77769
  225.                 |
  226.                 |-- etc                 d--x--x--x   2 root   root       
  227.                 |   |-- group           -r--r--r--   1 root   root      18
  228.                 |   |-- passwd          -r--r--r--   1 root   root      44
  229.                 |   `-- pathmsg         -r--r--r--   1 root   root     172
  230.                 |
  231.                 |-- lib                 d--x--x--x   2 root   root
  232.                 |   |-- ld-linux.so.1   -r-xr-xr-x   1 root   root   21375
  233.                 |   |-- libc.so.5.2.18  -rwxr-xr-x   1 root   root  536252
  234.                 |   `-- libc.so.5 -> libc.so.5.2.18
  235.                 |
  236.                 |-- pub                 dr-xr-xr-x   3 root   root
  237.                 |   `-- whatever
  238.                 |
  239.                 `-- welcome.msg         -rw-r--r--   1 root   root     323
  240.  
  241.  
  242.  
  243.     (c) Changed the home-directory of the anonymous ftp-account to
  244.         "/home/ano-ftp" by editing the file "/etc/passwd".
  245.  
  246.         ftp:*:11:11:Anonymous FTP:/home/ano-ftp:/bin/sh
  247.                                   ^^^^^^^^^^^^^
  248.                                   home-directory
  249.  
  250.  
  251.         These 3 steps were the basic setup and already enabled a
  252.         seperate ftp-areas for each of the 3 virtual hosts.
  253.         My actual job was a little bit more complicated in that I had
  254.         to enable disk-quotas (limiting the consumable disk-space per
  255.         user/group) in each incoming-diretory so the story continues:
  256.  
  257.  
  258.     (d) Enabled upload-areas in wu-ftpds config-file "/etc/ftpd/ftpaccess"
  259.  
  260.  
  261. 8<----- cut here 8<-----
  262. upload  /home/ano-ftp/www.sharpers.de  *         no
  263. upload  /home/ano-ftp/www.sharpers.de  /incoming yes sharpers ftp 0660 nodirs
  264. upload  /home/ano-ftp/www.swindlers.de *         no
  265. upload  /home/ano-ftp/www.swindlers.de /incoming yes swindler ftp 0660 nodirs
  266. upload  /home/ano-ftp/www.usurers.de   *         no
  267. upload  /home/ano-ftp/www.usurers.de   /incoming yes usurers  ftp 0660 nodirs
  268. #                                                |      |      |    |     |
  269. #                              uploads allowed --+      |      |    |     |
  270. #  uploaded files should be owned by this user ---------+      |    |     |
  271. #                           dito for the group ----------------+    |     |
  272. #             access rights for uploaded files ---------------------+     |
  273. #          creation of directories not allowed ---------------------------+
  274. 8<----- cut here 8<-----
  275.  
  276.  
  277.         Now, every file uploaded to those ftp-servers belongs to a
  278.         seperate user for which quotas can be enabled.
  279.  
  280.  
  281.     (e) Configured the disk-quotas
  282.  
  283.         Suggested readings: "/usr/doc/quotas.txt" and the Linux 
  284.         "Quota mini-HOWTO".
  285.  
  286.           * Added "usrquota=/etc/quota/ano-ftp.users" to the mount-options
  287.             of the partition "/home/an-ftp" is stored on in "/etc/fstab".
  288.  
  289.           * Created "/etc/quota/ano-ftp.users" via the "touch"-command
  290.  
  291.           * Switched on quotas by issuing "quotaon"
  292.  
  293.           * Set quotas with "edquota swindlers", etc.
  294.  
  295.             Quotas for user swindlers:
  296.             /dev/sdb8: blocks in use: 0, limits (soft = 0, hard = 10000)
  297.                        inodes in use: 1, limits (soft = 0, hard = 1000)
  298.  
  299.  
  300.             The corresponding disk-space depends on the size of the blocks
  301.             when you created the filesystem (standard is 1 block = 1 kb).
  302.  
  303.  
  304.   3. Availability
  305.  
  306.         The multihome-patch (20kb) for wu-ftpd can be downloaded from
  307.  
  308.     ftp://ftp.softhome.net/pub/users/brian/multihomed-wu-ftpd-2.4-23.patch
  309.  
  310.  
  311.         Please read it to get details about the copyright.
  312.  
  313.  
  314.         The sources for "wu-ftpd" itself are floating around in the net,
  315.         use archie to find the nearest server that carries them. Change
  316.         into the directory that is created when unpacking the sources and
  317.         type 
  318.  
  319.             patch < ../multihomed-wu-ftpd-2.4-23.patch
  320.  
  321.         to merge the patch into the sources. The FAQ for wu-ftpd is
  322.         available from
  323.  
  324.             http://www.hvu.nl/~koos/wu-ftpd-faq.html
  325.  
  326.  
  327. End of the Virtual-wu-ftpd mini-HOWTO
  328.  
  329.